package com.shuwei.location.permission;

import android.content.Context;
import android.content.pm.PackageManager;

/**
 * Created by Halohoop on 2017/10/24.
 */

public class Permissions {
    /**
     * 检查该应用的是否有对应的权限
     * @param context
     * @param permission 需要检查是否有权限的权限名称
     * @return {@link PackageManager#PERMISSION_GRANTED} if the given
     * pid/uid is allowed that permission, or
     * {@link PackageManager#PERMISSION_DENIED} if it is not.
     */
    public static int permissionCheck(Context context, String permission){
        return context.checkPermission(permission, android.os.Process.myPid(), android.os.Process.myUid());
    }
    /**
     * 检查该应用的是否有对应的权限,see also {@link Permissions#permissionCheck(Context, String)}
     * 有一个不满足就return false
     */
    public static boolean permissionsCheck(Context context, String[] permissions){
        for (int i = 0; i < permissions.length; i++) {
            if (PackageManager.PERMISSION_DENIED==permissionCheck(context, permissions[i])) {
                return false;
            }
        }
        return true;
    }
}
